<?php
/**
 * Вся работа с тендерами здесь
 *
 * @author kingop
 */
class ProjectsController extends CustomControllerAction {
    
    public function indexAction() {
        $project = DatabaseObject_Project::GetProjects($this->db);

        $this->view->projects=$project;
    }
     
    public function addprojectAction() {
         $request = $this->getRequest();
        $fp = new FormProcessor_ProjectAdd($this->db);

      
        $validate = $request->isXmlHttpRequest();

        if ($request->isPost()) {
            if ($validate) {
                $fp->validateOnly(true);
                $fp->process($request);
            } else if ($fp->process($request)) {
              $id =  $fp->project->getId();
               $this->_redirect($this->getCustomUrl(array('id' => $id ), 'viewproject'));
            }
        }

        if ($validate) {
            $json = array(
                'errors' => $fp->getErrors()
            );
            $this->sendJson($json);
        } else {
            $this->view->fp = $fp;
        }

       
        $this->view->fp = $fp;
    }
         
    public function editprojectAction() {
       $id = $this->getRequest()->getParam('id');
        
        $fp = new FormProcessor_ProjectEdit($this->db, $id);

        if ($this->getRequest()->isPost()) {
            if ($fp->process($this->getRequest())) {
                $this->_redirect($this->getUrl('index', 'projects'));
            }
        }
        
        $this->view->fp = $fp;
    }
    
     public function viewprojectAction() {
        $id = $this->getRequest()->getParam('id');
        $project = new DatabaseObject_Project($this->db);
        $project->load($id);
               
        
        $this->view->project = $project;
       
    }
    
    public function deleteprojectAction() {
        $id = $this->getRequest()->getParam('id');
        $project = new DatabaseObject_Project($this->db);
        $project->load($id); 
        $project->delete();
        
        $this->_redirect($this->getUrl( 'index','projects'));  
        
    }
    
     public function gettryingAction() {
        $tenderId = $this->getRequest()->getParam('id');
        
        echo "Участие. Тендер №: " . $tenderId;
    }
    
}

?>
